package br.edu.unibratec.Projeto.view;

import java.util.Date;
import java.util.List;

import br.edu.unibratec.Projeto.R;
import br.edu.unibratec.Projeto.controller.Evento;
import br.edu.unibratec.Projeto.controller.EventoDAO;
import br.edu.unibratec.Projeto.controller.Parada;
import br.edu.unibratec.Projeto.controller.ParadaDAO;
import br.edu.unibratec.Projeto.util.AgendadorReceiver;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class TelaCadastroPontosActivity extends Activity {

	private EditText edtPonto;
	private EditText edtDesc;
	private Parada parada;
	private ParadaDAO parDAO;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.cadastrar_pontos);
		
		edtPonto = (EditText) findViewById(R.id.editText1);
		edtDesc = (EditText) findViewById(R.id.editText2);
		
		if (getIntent().getSerializableExtra("paradaSelecionada") != null){
			parada = (Parada)getIntent().getSerializableExtra("paradaSelecionada");
			
			edtPonto.setText(parada.getNome());
			edtDesc.setText(parada.getDescricao());
		}
	}
	
	public void Cadastrar(View v){
		Log.d("Igor", "Cadastrar!!");
		ParadaDAO parDAO = new ParadaDAO(this);
		
		if (parada == null){
			Parada p = new Parada(0, edtPonto.getText().toString(), edtDesc.getText().toString(), 0, 0);
		parDAO.inserir(p);
		Toast.makeText(this, "Cadastrado", Toast.LENGTH_SHORT).show();
		finish();
		
		}else{
			parada.setNome((edtPonto.getText().toString()));
			parada.setDescricao(edtDesc.getText().toString());
					
			parDAO.atualizar(parada);
			finish();
		}
	}
	
	public void atualizarAgenda(){
		Log.d("Igor", "atualizar!!");
		List<Parada> paradas = (List<Parada>) parDAO.listaAtualizada();
	}
	
	
	public void Voltar(View v){
		Log.d("Igor", "voltar!!");
		Intent it = new Intent(this, ListaPontosActivity.class);
		startActivity(it);
	}
}
